<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>垫款业务规则表 管理</title>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>
<body class="iframeBody">
<form id="capAdvRuleInfo_form">
    <div class="fieldset1 tabel_col tabel_col_1 clearFix">
        <div class="fieldBox col_100">
            <div class="label">垫款规则名称</div>
            <div class="field">
                <input name="ruleNm" id="ruleNm" type="text" class="ui-textbox"
                       value="${capAdvRuleInfoVO.ruleNm}" validate="{required:true}">
                <span class="requiredSymbol">*</span>
                <input type="text" style="display: none;" id="ruleTypCd" name="ruleTypCd"
                       value="${capAdvRuleInfoVO.ruleTypCd == null ? "1":capAdvRuleInfoVO.ruleTypCd}">
            </div>
        </div>
        <div class="fieldBox col_100">
            <div class="label">启用状态</div>
            <div class="field">
                <input type="radio" name="ruleStsCd" id="ruleStsCd_0" <c:if test="${not empty capAdvRuleInfoVO and capAdvRuleInfoVO.ruleStsCd == '1'}">checked</c:if>/><span class="requiredSymbol">开启</span>&nbsp;&nbsp;&nbsp;&nbsp;
                <input type="radio" name="ruleStsCd" id="ruleStsCd_1" <c:if test="${not empty capAdvRuleInfoVO and capAdvRuleInfoVO.ruleStsCd == '0'}">checked</c:if> /><span class="requiredSymbol">关闭</span>
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_100">
            <div class="label">垫款日期类型</div>
            <div class="field">
                <input name="dtTypCd" id="dtTypCd"
                       data-value="${capAdvRuleInfoVO.dtTypCd}" validate="{required:true}"
                       placeholder="请选择" ltype="combobox">
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_100">
            <div class="label">垫款周期</div>
            <div class="field">
                <input name="advCycCd" id="advCycCd"
                       data-value="${capAdvRuleInfoVO.advCycCd}" validate="{required:true}"
                       placeholder="请选择" ltype="combobox">
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_100">
            <div class="label">垫款时间</div>
            <div class="field">
                <input name="advTmCd" id="advTmCd"
                       data-value="${capAdvRuleInfoVO.advTmCd}" validate="{required:true,select:true}"
                       placeholder="请选择" ltype="combobox">
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_100">
            <div class="label">垫款租金范围</div>
            <div class="field">
                <input name="advMinAmt" id="advMinAmt" type="text" class="ui-textbox"
                       data-value="${capAdvRuleInfoVO.advMinAmtStr}" validate="{number:true}">
                ~
                <input name="advMaxAmt" id="advMaxAmt" type="text" class="ui-textbox"
                       data-value="${capAdvRuleInfoVO.advMaxAmtStr}" validate="{number:true}">
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_100">
            <div class="label">垫款逾期天数</div>
            <div class="field">
                <input name="minOvdDay" id="minOvdDay" type="text" class="ui-textbox"
                       value="${capAdvRuleInfoVO.minOvdDay}" validate="{number:true}">
                ~
                <input name="maxOvdDay" id="maxOvdDay" type="text" class="ui-textbox"
                       value="${capAdvRuleInfoVO.maxOvdDay}" validate="{number:true}">
                <span class="requiredSymbol">*</span>
            </div>
        </div>

        <div class="fieldBox col_100">
            <div class="label">垫款期数</div>
            <div class="field">
                <input name="advPd" id="advPd" type="text" class="ui-textbox"
                       value="${capAdvRuleInfoVO.advPd}" validate="{required:true,number:true}">期
                &nbsp;&nbsp;&nbsp;&nbsp;
                <input type="checkbox" name="isAllAdv" id="isAllAdv"
                       <c:if test="${capAdvRuleInfoVO.isAllAdv == 1}">checked</c:if>>
                <span class="requiredSymbol">全垫</span>
            </div>
            <span class="requiredSymbol">*</span>
        </div>
        <div class="fieldBox col_100">
            <div class="label">垫款基数</div>
            <div class="field">
                <input name="advBaseCd" id="advBaseCd"
                       data-value="${capAdvRuleInfoVO.advBaseCd}" validate="{required:true}"
                       placeholder="请选择" ltype="combobox">
                <span class="requiredSymbol">*</span>
            </div>
            <span class="requiredSymbol">*</span>
        </div>
        <div class="fieldBox col_100">
            <div class="label">垫款方式</div>
            <div class="field">
                <input name="advTypCd" id="advTypCd"
                       data-value="${capAdvRuleInfoVO.advTypCd}" validate="{required:true}"
                       placeholder="请选择" ltype="combobox">
                <span class="requiredSymbol">*</span>
            </div>
        </div>
    </div>
    <c:if test="${not empty prjIdList}">
        <div id="ligergrid" class="sq-grid" style="display: block"></div>
    </c:if>
    <div class="btnsBox">
        <span id="saveCapAdvRuleInfo_Btn" class="sq-button sq-button-round l-dialog-btn-ok">保存</span>
        <input type="reset" id="resetBtn" class="l-button l-button-reset Hide">
    </div>
</form>
<script>
    var ligerForm = null ;
    var prjIdList = '${prjIdList}';
    $(function () {
        var capAdvRuleInfoId = "${capAdvRuleInfoVO.id}";//主键ID
        $('#isAllAdv').ligerCheckBox();
        $('#ruleStsCd_0').ligerRadio();
        $('#ruleStsCd_1').ligerRadio();
//        var form = liger.get("capAdvRuleInfo_form");
        ligerForm = $("#capAdvRuleInfo_form").ligerForm({
            validate: true
        });

        //垫款日期类型
        $("#dtTypCd").ligerComboBox({
            data: ${advDtKvList},
            valueField: 'key',
            textField:'value'
        });
        //垫款周期
        $("#advCycCd").ligerComboBox({
            data: ${advPeriodKVList},
            valueField: 'key',
            textField:'value'
        });
        //垫款基数
        $("#advBaseCd").ligerComboBox({
            data: ${advBaseCdKvList},
            valueField: 'key',
            textField:'value'
        });
        //垫款方式
        $("#advTypCd").ligerComboBox({
            data: ${advWayKvList},
            valueField: 'key',
            textField:'value'
        });

        //垫款时间
        $("#advTmCd").ligerComboBox({
            data: ${advTmKvList},
            valueField: 'key',
            textField:'value'
        });

        //设置逾期期数验证
        <c:if test="${not empty capAdvRuleInfoVO and capAdvRuleInfoVO.isAllAdv == '1'}">
            ligerForm.setFieldValidate("advOvdPdCd", {
                required: false
            });
            liger.get("advPd").setDisabled(true);
            //$("#advPd").attr("disabled",true);
        </c:if>
        <c:if test="${not empty prjIdList}">
        $("#ligergrid").ligerGrid({
            url:'<%=path%>/capital/capAdvRuleInfo/initFncPrjListPage.do?prjIdList='+prjIdList,
            method:'GET',
            columns: [
                {
                    display: '项目名称', name: 'fncprjnm', minWidth: 100, align: 'center', enabledSort: false
                },
                {
                    display: '生效时间', name: 'crttm', minWidth: 100, align: 'center', enabledSort: false,render:renderDate
                },
                {
                    display: '添加人', name: 'crtpsnecd', minWidth: 100, align: 'center', enabledSort: false,
                },
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            width: '100%',
            height: '100%',
            heightDiff: -2,
            allowUnSelectRow: true,
            alternatingRow: true,
            rownumbers: true,
            enabledEdit: false,
            usePagerOnLessPagesize: true
        });
        </c:if>
        /*垫款期数*/
        $("#isAllAdv").change(function(){
            if(this.checked){
                liger.get("advPd").setDisabled(true);
                //$("#advPd").attr("disabled",true);
                ligerForm.setFieldValidate("advPd", {
                    required: false
                });
            }else{
                liger.get("advPd").setEnabled(true);
                //$("#advPd").attr("disabled",false);
                ligerForm.setFieldValidate("advPd", {
                    required: true
                });
            }
        });

        /*保存*/
        $("#saveCapAdvRuleInfo_Btn").click(function (event) {
            if (!ligerForm.valid()) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
                return false; //验证不通过，不执行以下代码
            }
            if($("#advMinAmt").val() == '' && $("#advMaxAmt").val() == '' && $("#minOvdDay").val() == '' && $("#maxOvdDay").val() == ''){
                $.ligerDialog.SQalert({content: LogUtils.LOG_CAP_ADV_RULE_RENK, SQ_type: "warning"});
                return false;
            }
            var data = ligerForm.getData();
            var ruleTypCd = $("#ruleTypCd").val();
            data['ruleTypCd'] = ruleTypCd ;
            if(data.isAllAdv){
                data.isAllAdv = 1 ;
            }else{
                data.isAllAdv = 0 ;
            }

            if(liger.get('ruleStsCd_0').checked){
                data.ruleStsCd = 1 ;
            }else{
                data.ruleStsCd = 0 ;
            }
            $.ligerDialog.hide();
            var _url;
            if (capAdvRuleInfoId == '') {//新增
                _url = '<%=path%>/capital/capAdvRuleInfo/add.do';
            } else {//修改
                _url = '<%=path%>/capital/capAdvRuleInfo/modify.do?id=' + capAdvRuleInfoId;
            }
            var wait_dialog;
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: data,
                url: _url,
                beforeSend: function () {
                    wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                },
                success: function (msg) {
                    wait_dialog.close();
                    if (msg.success == 1) {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                        parent.$("#clearBtn").click();
                        parent.$("#searchBtn").click();
                        frameElement.dialog.close();

                        //$("#resetBtn").click();
                        //回调刷新列表
                        //var callback=frameElement.W2W.callback;
                        //Remove_navTab();
                        //callback();
                    } else {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        });
    });

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }
</script>
</body>
</html>
